<?php 
class newsletter_models_admin extends CI_Model{
	public function __construct(){
		$this->load->database();
	}
	public function save($newsletter){
		//creer newsletter
		$this->db->insert('newslettre', $newsletter);
		//prendre id auto increment
		return $this->db->insert_id();
	}

	public function edit($newsletter){
		//creer newsletter
		$this->db->update('newslettre', $newsletter, "id = {$newsletter->id}");
	}
	public function sent($email){
		//creer newsletter
		$data=array('sEmail'=>$email,
				'sCreateDate'=>1,
				'sCreateDate'=>strtotime('now')
		);
		$this->db->update('newslettre', $data, "sEmail='$email'");
	}
	public function list_newslettre() {
		$query = $this->db->get('newslettre');
		return $query->result();
	}
	public function get_newslettre($id=0){
		$newsttre=new stdClass;
		$newsttre->fromname=
		$newsttre->fromemail=
		$newsttre->subject=
		$newsttre->body='';
		if($id)
			$query = $this->db->get_where('newslettre',array('id' => $id),1);
		else 
			$query = $this->db->order_by("date_create", "desc")->get('newslettre',1);
		
		if($query->num_rows()){
			$row= $query->result();
			return $row[0];
		}
			return $newsttre;
	}
}